<?php
session_start();
include("../include/config.inc.php");

$todo=$_REQUEST["todo"];
if(isset($todo) && $todo=="todo"){
	$mobile = $_POST['mobile'];
	$smscode = $_POST['smscode'];
	$password = $_POST['password'];
	$configpass = $_POST['configpass'];
	$code = $_POST['code'];
	$verify = $_SESSION['session_verify'];
	//$sms = $_SESSION['session_smscode'];
	
	if($code==""){
		echo "<script>alert('请输入验证码！');history.back(-1);</script>";
		exit;
	}
	if($code<>$verify){
		echo "<script>alert('请输入正确的验证码！');history.back(-1);</script>";
		exit;
	}
	if($mobile==""){
		echo "<script>alert('请输入手机号码！');history.back(-1);</script>";
		exit;
	}
	if($smscode==""){
		echo "<script>alert('请输入手机短信验证码！');history.back(-1);</script>";
		exit;
	}
	if($smscode<>'000000'){
		echo "<script>alert('手机短信验证码输入不正确！');history.back(-1);</script>";
		exit;
	}
	if($password==""){
		echo "<script>alert('请输入6-20位的新密码！');history.back(-1);</script>";
		exit;
	}
	if($configpass==""){
		echo "<script>alert('请确认新密码！');history.back(-1);</script>";
		exit;
	}
	if($password<>$configpass){
		echo "<script>alert('两次密码输入不一致！');history.back(-1);</script>";
		exit;
	}
	$passwor=md5($password);
	$updatetime=date("Y-m-d H:i:s");
	$ip=getIP();	
	$sql="update ".tablepre."member set password='$passwor',updatetime='$updatetime',ip='$ip' where mobile=$mobile";
	$db->query($sql);
	if(!$db->error())
	{
		echo "<script>alert('密码重置成功，请重新登陆！');location.href='login.php';</script>";
		$db->close();
		exit;
	}
	else
	{
		echo "<script>alert('数据库出错，请重试。');location.href='findpassword.php';</script>";		
		$db->close();
		exit;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<title>重置密码</title>
<link rel="stylesheet" type="text/css" href="../css/login.css">
<script type="text/javascript" src="../js/clientwidth.js"></script>
</head>

<body>
<header class="header" style="display:block;"><span class="goback"></span>重置密码<span class="close"></span></header>
<form id="login-form" action="" method="post">
<input name="todo" type="hidden" value="todo">
<section class="loginpage">
	<div class="loginlogo"><img src="../images/logo.png" /></div>
	<div class="loginform">
		<div class="input-container">
            <input id="mobile" name="mobile" type="text" placeholder="请输入手机号码" maxlength="11" style="border-radius:5px 5px 0px 0px;background-position:0px 3px;">
        </div>
		<div class="input-container">
            <input id="smscode" name="smscode" type="text" placeholder="请输入短信验证码" maxlength="6" style="border-radius:0px 0px 0px 0px;border-top:none;border-bottom:none;">
            <span class="code-box"><a href="#" target="_blank">获取短信验证码</a></span>
        </div>
		<div class="input-container">
            <input id="password" name="password" type="password" placeholder="请输入6-20位的新密码" minlength="6" maxlength="20" style="border-radius:0px 0px 0px 0px;">
        </div>
		<div class="input-container">
            <input id="configpass" name="configpass" type="password" placeholder="请确认新密码" minlength="6"  maxlength="20" style="border-radius:0px;border-top:none;">
        </div>
		<div class="input-container">
            <input id="code" name="code" type="text" placeholder="请输入验证码" maxlength="4" style="border-radius:0px 0px 5px 5px;border-top:none;">
            <span class="code-box"><img id="imgCode" src="../include/verify.php" alt="请输入验证码" style="border-radius:0px 0px 5px 0px;"></span>
        </div>
	</div>
	<div class="notice"></div>
	<div class="input-submit"><input name="s" type="submit" class="sub-input" value="确认重置密码" /></div>
	<div class="quick-nav">
    	<a href="loginbysms.php" class="findpwd">短信登陆</a>
        <a href="register.php" class="quickReg">快速注册</a>
    </div>
    <div class="quick-login">
        <h4>其他登录方式</h4>
        <a href="login.php"><i class="icon icon-user"></i><br>账号</a>
		<a href="javascript:;"><i class="icon icon-qq"></i><br>QQ</a>
        <a href="javascript:;"><i class="icon icon-wx"></i><br>微信</a>
    </div>
</section>
</form>
<script>
if (document.body.clientWidth > 500) {
	$('.loginpage').css({
		width: 500,
		margin: '0 auto',
	});
}
</script>
</body>
</html>